Skip to content

Validate warehouse location name length instead of silently truncating it - #834

Merged
pylipp merged 4 commits into
masterfrom
fix/location-name-length-validation
Jul 28, 2026
Merged

Validate warehouse location name length instead of silently truncating it#834
pylipp merged 4 commits into
masterfrom
fix/location-name-length-validation

Conversation

@vahidbazzaz

Copy link
Copy Markdown
Contributor

Summary

  • "Edit Warehouses" let you save a location name longer than the DB column (locations.label varchar(20)), which MySQL silently truncated with no feedback.
  • Widens locations.label to varchar(50) via phinx migration, and adds matching client-side (jQuery Validate, blocks submit) and server-side (mb_strlen check, throws a clear exception) validation, plus a tooltip explaining why the limit exists (mobile navigation speed for warehouse/distribution teams).
  • Along the way, found and fixed two pre-existing latent bugs the change surfaced:
    • The data-max-count character counter's jQuery plugin (jquery.simplyCountable.js) existed in the repo but was never loaded on any page — no field had ever used the maxlength option before, so this was silently dead code.
    • The counter's label text was hardcoded in Dutch ("tekens over van") instead of using the already-seeded-but-unused English translate key cms_form_charactersleft.

Test plan

  • Applied the migration locally and confirmed locations.label is varchar(50) via SHOW COLUMNS
  • Scripted the real login + form POST flow against the running app: a 51-char name is rejected with the new error and never reaches the DB; a 50-char name saves in full, untruncated
  • Added cypress/e2e/1_feature_tests/6_1_Warehouse_Locations.js covering both cases; ran it against the live app in a real (headless) browser — both pass
  • Manually confirmed in-browser: inline error + tooltip render correctly, and the counter now shows English text ("50 characters left from 50") instead of Dutch

…g it

Creating/editing a warehouse location let users type a name longer than
the DB column, which MySQL then silently truncated on save with no
feedback. Widens locations.label to varchar(50) and adds matching
client + server validation so an over-limit name is rejected with a
clear inline error (plus a tooltip explaining the limit) instead of
being cut off.

Also fixes two latent bugs this surfaced: the data-max-count character
counter's jQuery plugin was never actually loaded on any page, and its
counter text was hardcoded in Dutch with an unused English translate
key sitting right next to it.
@vahidbazzaz

Copy link
Copy Markdown
Contributor Author

@vahidbazzaz vahidbazzaz self-assigned this Jul 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR prevents warehouse location names from being silently truncated by aligning database limits with explicit validation and UI feedback in the CMS “Edit Warehouses” flow.

Changes:

  • Widen locations.label from varchar(20) to varchar(50) via a new Phinx migration.
  • Add server-side length validation in include/locations_edit.php and client-side maxlength enforcement for data-max-count fields via jQuery Validate.
  • Ensure the character counter works end-to-end by loading jquery.simplyCountable.js and using the existing translate key for “characters left”.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
templates/cms_form_url.tpl Removes an unused/legacy field template variant.
templates/cms_form_text.tpl Switches counter label text to use the cms_form_charactersleft translate key.
templates/cms_form_number.tpl Switches counter label text to use the cms_form_charactersleft translate key.
templates/cms_form_location.tpl Removes an unused/legacy field template variant.
templates/cms_footer.tpl Loads jquery.simplyCountable.js and bumps magic.js cache-buster version.
include/locations_edit.php Adds server-side max-length validation and sets maxlength + tooltip on the Label field.
db/migrations/20260725095602_widen_locations_label_column.php Migration to widen locations.label to 50 chars (with down migration back to 20).
cypress/e2e/1_feature_tests/6_1_Warehouse_Locations.js Adds Cypress coverage for boundary cases (50 accepted, 51 rejected).
assets/js/magic.js Adds jQuery Validate maxlength rules for all [data-max-count] fields to block submit when over limit.

Comment thread cypress/e2e/1_feature_tests/6_1_Warehouse_Locations.js
@pylipp
pylipp merged commit b0d1170 into master Jul 28, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants